package com.youpai.platform.vulture.service.service.impl;

import com.youpai.platform.common.util.cache.Cache;
import com.youpai.platform.common.util.id.IdGenerator;
import com.youpai.platform.vulture.service.constant.PortConstants;
import com.youpai.platform.vulture.service.service.VultureConfigService;
import com.youpai.platform.vulture.service.util.CacheKeyUtil;
import com.youpai.platform.vulture.web.entity.req.GetVultureHandshakeTokenReq;
import com.youpai.platform.vulture.web.entity.resp.GetVultureHandshakeTokenResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @date: 2022/7/9 21:36
 * @author: Anna
 * @version: 1.0
 * @description: vultureConfigServiceImpl
 */
@Slf4j
@Service
public class VultureConfigServiceImpl implements VultureConfigService {

    private static final String ipAddress = "139.198.163.197";

    @Resource
    @Qualifier(value = "redisCache")
    private Cache<String, String> handShakeTokenCache;

    @Override
    public GetVultureHandshakeTokenResp getVultureHandshakeToken(GetVultureHandshakeTokenReq req) {
        String handshakeToken = IdGenerator.generateId().toString();
        handShakeTokenCache.putValue(CacheKeyUtil.getHandShakeToken(req.getDeviceId()), handshakeToken);
        log.info("握手请求，deviceId - {} , token - {}", req.getDeviceId(), handshakeToken);
        return new GetVultureHandshakeTokenResp()
                .setVultureToken(handshakeToken)
                .setVultureGateWayIp(ipAddress)
                .setVultureGateWayPort(PortConstants.TCP_PORT);
    }
}
